import request from '@/config/axios'
import type { ClassType, classAddType, ClassChildType } from './type'

// 分类 horizon-system/sys/category/rootList
export const getClassList = (params: any): Promise<LoginResponse<ClassType>> => {
  return request.get({ url: '/sys/category/rootList', params })
}
//子级
export const getClassChildList = (params: any): Promise<LoginResponse<ClassChildType>> => {
  return request.get({ url: '/sys/category/childList', params })
}
//添加 /horizon-system/sys/category/add
export const categoryAdd = (data: any): Promise<LoginResponse<classAddType>> => {
  const headers = {
    'Content-Type': 'application/json'
  }
  return request.post({ url: '/sys/category/add', data, headers: headers })
}
//通过id删除 /sys/category/delete
export const categoryRemoveId = (params: any): Promise<LoginResponse<classAddType>> => {
  const headers = {
    'Content-Type': 'application/x-www-form-urlencoded'
  }
  return request.delete({ url: '/sys/category/delete', params, headers: headers })
}
//批量删除
export const categoryDeleteBatch = (params: any): Promise<LoginResponse<classAddType>> => {
  const headers = {
    'Content-Type': 'application/x-www-form-urlencoded'
  }
  return request.delete({ url: '/sys/category/deleteBatch', params, headers: headers })
}
//编辑
export const categoryEdit = (data: any): Promise<LoginResponse<classAddType>> => {
  const headers = {
    'Content-Type': 'application/json'
  }
  return request.post({ url: '/sys/category/edit', data, headers: headers })
}
//根据字典code加载字典text 返回 sys/dict/loadDictItem/{dictCode}
// export const categoryLoadDictItem = (params: any): Promise<LoginResponse<classAddType>> => {
//   return request.get({ url: `/sys/dict/loadDictItem/${params}` })
// }
//根据表名——显示字段-存储字段 pid 加载树形数据  /sys/dict/loadTreeData
export const categoryLoadTreeData = (params: any): Promise<LoginResponse<classAddType>> => {
  return request.get({ url: '/sys/dict/loadTreeData', params })
}
//类字典控件数据回显[表单页面] /sys/category/loadDictItem
export const categoryLoadDictItem = (params: any): Promise<LoginResponse<classAddType>> => {
  return request.get({ url: '/sys/category/loadDictItem', params })
}
